package com.bj.dz.service.impl;

import com.bj.dz.entity.StationBuilding;
import com.bj.dz.mapper.StationBuildingMapper;
import com.bj.dz.service.StationBuildingService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class StationBuildingServiceImpl implements StationBuildingService {

    @Resource
    private StationBuildingMapper stationBuildingMapper;

    public StationBuilding getStationBuildingById(Integer id){
        return stationBuildingMapper.getStationBuildingById(id);
    }

    public List<StationBuilding>	getStationBuildingListByMap(Map<String,Object> param){
        return stationBuildingMapper.getStationBuildingListByMap(param);
    }

    public Integer getStationBuildingCountByMap(Map<String,Object> param){
        return stationBuildingMapper.getStationBuildingCountByMap(param);
    }

    @Transactional
    public boolean addStationBuilding(StationBuilding stationBuilding){
            return stationBuildingMapper.insertStationBuilding(stationBuilding)>0?true:false;
    }

    @Transactional
    public boolean modifyStationBuilding(StationBuilding stationBuilding){
        return stationBuildingMapper.updateStationBuilding(stationBuilding)>0?true:false;
    }

    @Transactional
    public boolean deleteStationBuildingById(Integer id){
        return stationBuildingMapper.deleteStationBuildingById(id)>0?true:false;
    }

    public Page<StationBuilding> queryStationBuildingPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = stationBuildingMapper.getStationBuildingCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<StationBuilding> stationBuildingList = stationBuildingMapper.getStationBuildingListByMap(param);
        page.setRows(stationBuildingList);
        return page;
    }

}
